package com.sci.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sci.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    @Update("UPDATE user SET balance = balance - #{amount} WHERE wechat_id = #{wechatId} AND balance >= #{amount}")
    int deductBalance(@Param("wechatId") String wechatId, @Param("amount") Double amount);

    @Select("SELECT * FROM user WHERE wechat_id = #{wechatId}")
    User selectByWechatId(String wechatId);
}
